const loaderUtils = require('loader-utils')
function loader(source){
  let str = `
    let style = document.createElement('style')
    style.innerHTML = ${JSON.stringify(source)}
    document.head.appendChild(style)
  `
  return str
}

loader.pitch = function(remainingRequst){
  /**
   * pitch有返回值的话，后面的loader不会在执行，并且当前loader也不会执行了
   * require(${loaderUtils.stringifyRequest(this,'!!'+remainingRequst)})：
   *    require(css-loader!less-loader!../2.png)
   *    会走行内loader逻辑，然后执行less-loader-->css-loader-->require-->返回值赋给style.innerHTML
   */
  let str = `
    let style = document.createElement('style')
    style.innerHTML = require(${loaderUtils.stringifyRequest(this,'!!'+remainingRequst)})
    document.head.appendChild(style)
  `
  return str
}

module.exports = loader